//
//  CategoryV1Cell.m
//  jipin
//
//  Created by chuangjia on 10/6/15.
//  Copyright (c) 2015 liuchengbin. All rights reserved.
//

#import "CategoryV1Cell.h"
#import "ZUIImageView.h"
#import "UIButtonView.h"
@interface CategoryV1Cell()
{
    
}
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) ZUIImageView *pimageView;
@property(nonatomic,strong)RTLabel *skuNameLabel;
@property(nonatomic,strong)UIView *skuNameLine;
@property(nonatomic,strong)RTLabel *skuNameContent;
@property(nonatomic,strong)RTLabel *cateLabel;
@property(nonatomic,strong)RTLabel *brandLabel;
@property (nonatomic, strong) UIButtonView *btnLikeV;
@property (nonatomic, strong) UIButtonView *btnReplyV;
@property (nonatomic, strong) UIView *commentView;
@property(nonatomic,strong)UILabel *priceLabel;
@property(nonatomic,strong)UILabel *photoLabel;
@property(nonatomic,strong)UIButton *tagBtn;
@property(nonatomic,strong)UILabel *userLable;
@property(nonatomic,strong)UILabel *timeLable;
@property(nonatomic,strong)UIImageView *shaidanView;
@property(nonatomic,strong)UIImageView *sdView;
@property(nonatomic,strong)UIImageView *lineView;
@end


@implementation CategoryV1Cell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _bgView = [[UIView alloc] initWithFrame:CGRectZero];
        _bgView.backgroundColor =[UIColor clearColor];
        [self.contentView addSubview:_bgView];
        //
        UITapGestureRecognizer* singleRecognizer= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom)];
        _pimageView =[[ZUIImageView alloc] initWithFrame:CGRectZero];
        _pimageView.backgroundColor =UIColorFromRGB(0xffffff);
        _pimageView.userInteractionEnabled =YES;
        _pimageView.contentMode = UIViewContentModeScaleAspectFit;
        [_pimageView addGestureRecognizer:singleRecognizer];
        [_bgView addSubview:_pimageView];
        singleRecognizer=nil;
        //
        
        UITapGestureRecognizer* singleRecognizer1= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom)];
        _skuNameLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _skuNameLabel.backgroundColor = [UIColor clearColor];
        _skuNameLabel.textColor = [UIColor darkGrayColor];
        _skuNameLabel.textAlignment = NSTextAlignmentLeft;
        _skuNameLabel.font = FONT(16);
        _skuNameLabel.lineSpacing = LSpacing;
        _skuNameLabel.userInteractionEnabled =YES;
        [_skuNameLabel addGestureRecognizer:singleRecognizer1];
        [_bgView addSubview:_skuNameLabel];
        singleRecognizer1=nil;
        
        _skuNameLine = [[UIView alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH, 0, PHOTO_FRAME_WIDTH*3, 1)];
        _skuNameLine .backgroundColor =[UIColor lightGrayColor];
        [_bgView addSubview:_skuNameLine];
        //
        UITapGestureRecognizer* singleRecognizer2= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom)];
        _skuNameContent =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _skuNameContent.backgroundColor = [UIColor clearColor];
        _skuNameContent.textColor = [UIColor darkGrayColor];
        _skuNameContent.textAlignment = NSTextAlignmentLeft;
        _skuNameContent.font = FONT(14);
        _skuNameContent.lineSpacing =LSpacing;
        _skuNameContent.userInteractionEnabled =YES;
        [_skuNameContent addGestureRecognizer:singleRecognizer2];
        [_bgView addSubview:_skuNameContent];
        singleRecognizer2=nil;
        //
        UITapGestureRecognizer* singleRecognizer3= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom3)];
        _cateLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _cateLabel.backgroundColor = [UIColor clearColor];
        _cateLabel.textColor = UIColorFromRGB(0x285790);
        _cateLabel.textAlignment = NSTextAlignmentLeft;
        _cateLabel.font = FONT(14);
        _cateLabel.lineSpacing =LSpacing;
        _cateLabel.userInteractionEnabled =YES;
        [_cateLabel addGestureRecognizer:singleRecognizer3];
        [_bgView addSubview:_cateLabel];
        singleRecognizer3=nil;
        
        UITapGestureRecognizer* singleRecognizer4= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom4)];
        _brandLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        _brandLabel.backgroundColor = [UIColor clearColor];
        _brandLabel.textColor = UIColorFromRGB(0x285790);
        _brandLabel.textAlignment = NSTextAlignmentLeft;
        _brandLabel.font = FONT(14);
        _brandLabel.lineSpacing = 6.0;
        _brandLabel.userInteractionEnabled =YES;
        [_brandLabel addGestureRecognizer:singleRecognizer4];
        [_bgView addSubview:_brandLabel];
        singleRecognizer4=nil;
        //
        _commentView = [[UIView alloc] initWithFrame:CGRectZero];
        _commentView.backgroundColor =[UIColor clearColor];
        [_bgView addSubview:_commentView];
        //
        _btnLikeV = [[UIButtonView alloc] initWithFrame:CGRectZero];
        _btnLikeV.backgroundColor =  [UIColor clearColor];
       
        __weak typeof (self) wSelf = self;
        [_btnLikeV setCallBack:^(BEventType t, UIView *v, id data, id key) {
            [wSelf likeAction:nil];
        }];
        [_bgView addSubview:_btnLikeV];
        
        _btnReplyV = [[UIButtonView alloc] initWithFrame:CGRectZero];
        _btnReplyV.backgroundColor =  [UIColor clearColor];
        [_btnReplyV setCallBack:^(BEventType t, UIView *v, id data, id key) {
            [wSelf commentAction:nil];
        }];
        [_bgView addSubview:_btnReplyV];
        
        
        _priceLabel =[[UILabel alloc] initWithFrame:CGRectZero];
        _priceLabel.backgroundColor = [UIColor clearColor];
        _priceLabel.textColor = [UIColor grayColor];
        _priceLabel.textAlignment = NSTextAlignmentLeft;
        _priceLabel.font = FONT(12);
        [_bgView addSubview:_priceLabel];
        
        _photoLabel =[[UILabel alloc] initWithFrame:CGRectZero];
        _photoLabel.backgroundColor = [UIColor grayColor];
        _photoLabel.alpha=0.5;
        _photoLabel.textColor = [UIColor whiteColor];
        _photoLabel.textAlignment = NSTextAlignmentCenter;
        _photoLabel.font = FONT(14);
        _photoLabel.layer.cornerRadius = 3;//(值越大，角就越圆)
        _photoLabel.layer.masksToBounds = YES;
        [_bgView addSubview:_photoLabel];
        
        _tagBtn =[UIButton buttonWithType:UIButtonTypeCustom];
        _tagBtn.backgroundColor = [UIColor whiteColor];
        [_tagBtn setTitleColor:UIColorFromRGB(0x285790) forState:UIControlStateNormal];
        [_tagBtn addTarget:self action:@selector(categoryAction1:) forControlEvents:UIControlEventTouchUpInside];
        _tagBtn.titleLabel.font = FONT(12);
        _tagBtn.layer.cornerRadius = 3;//(值越大，角就越圆)
        _tagBtn.layer.masksToBounds = NO;
        _tagBtn.layer.borderColor =UIColorFromRGB(0x285790).CGColor;
        _tagBtn.layer.borderWidth =0.5;
        [_bgView addSubview:_tagBtn];
        
        _shaidanView =[[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_shaidanView];
        
        _sdView =[[UIImageView alloc] initWithFrame:CGRectZero];
        [self.contentView addSubview:_sdView];
        
        //
        UITapGestureRecognizer* singleRecognizer5= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFromUser)];
        _userLable =[[UILabel alloc] initWithFrame:CGRectZero];
        _userLable.backgroundColor = [UIColor clearColor];
        _userLable.textColor = UIColorFromRGB(0x285790);
        _userLable.textAlignment = NSTextAlignmentLeft;
        _userLable.font = FONT(12);
        _userLable.numberOfLines=0;
        _userLable.userInteractionEnabled=YES;
        [_userLable addGestureRecognizer:singleRecognizer5];
        [_bgView addSubview:_userLable];
        singleRecognizer5=nil;
        
        _timeLable =[[UILabel alloc] initWithFrame:CGRectZero];
        _timeLable.backgroundColor = [UIColor clearColor];
        _timeLable.textColor = [UIColor grayColor];
        _timeLable.textAlignment = NSTextAlignmentLeft;
        _timeLable.font = FONT(12);
        _timeLable.numberOfLines=0;
        [_bgView addSubview:_timeLable];
        //
    
        _lineView =[[UIImageView alloc] initWithFrame:CGRectZero];
        _lineView.image =[UIImage imageNamed:@"line_xu.png"];
        [self.contentView addSubview:_lineView];
    }
    return self;
}
-(void)dealloc
{
    self.actionBlock=nil;
    self.data=nil;
    self.other=nil;
    self.indexPath=nil;
    
    [self.pimageView removeFromSuperview];
    self.pimageView=nil;
    [self.skuNameLabel removeFromSuperview];
    self.skuNameLabel=nil;
    
    [self.skuNameLine removeFromSuperview];
    self.skuNameLine=nil;
    
    [self.skuNameContent removeFromSuperview];
    self.skuNameContent=nil;
    
    [self.cateLabel removeFromSuperview];
    self.cateLabel=nil;
    
    [self.brandLabel removeFromSuperview];
    self.brandLabel=nil;
    
    [self.btnLikeV removeFromSuperview];
    self.btnLikeV=nil;
    
    [self.btnReplyV removeFromSuperview];
    self.btnReplyV=nil;
    
    [self.commentView removeFromSuperview];
    self.commentView=nil;
    [self.priceLabel removeFromSuperview];
    self.priceLabel=nil;
    [self.photoLabel removeFromSuperview];
    self.photoLabel=nil;
    
    self.tagBtn=nil;
    [self.userLable removeFromSuperview];
    self.userLable=nil;
    
    [self.timeLable removeFromSuperview];
    self.timeLable=nil;
    
    [self.shaidanView removeFromSuperview];
    self.shaidanView=nil;
    
    [self.sdView removeFromSuperview];
    self.sdView=nil;
    
    [self.lineView removeFromSuperview];
    self.lineView=nil;
    
    //    DLog(@"%s", __PRETTY_FUNCTION__);
}
- (void)layoutSubviews
{
    [super layoutSubviews];
    _bgView.frame =CGRectMake(0, 0, self.bounds.size.width, self.bounds.size.height);
    
}
- (void)drawRect:(CGRect)rect {

    [super drawRect:rect];
     self.lineView.frame =CGRectMake(0,self.bounds.size.height-1, DEVICE_WIDTH, 1);
}
/// 根据数据模型来显示内容
- (void)showInfo:(id)model other:(id)other key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.other =other;
    self.key =key;
    self.data =model;
    [self showInfo:model indexPath:indexPath];
}
- (void)showInfo:(id)model key:(id)key indexPath:(NSIndexPath *)indexPath
{
    self.key = key;
     self.data =model;
    [self showInfo:model indexPath:indexPath];
}
- (void)showInfo:(id)model indexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dict =(NSDictionary*)model;
    self.data =model;
    self.indexPath=indexPath;
    float fTop = 0;
    fTop += PHOTO_FRAME_WIDTH*2+PHOTO_TIME_PADDING ;
   
    NSString * strURL = [[NSString stringWithFormat:@"%@", [dict objectForKey:@"largePicURL"]] replaceNullString];
    if (strURL&&strURL.length>0) {
        _pimageView.frame = CGRectMake(PHOTO_FRAME_WIDTH*4, fTop, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*8 ,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*8);
        _pimageView.imageUrl =strURL;
        _pimageView.placeholderImage =[UIImage imageNamed:@"image.png"];
    }
    int is_shaidan =[[dict objectForKey:@"is_shaidan"] intValue];
    if (is_shaidan==1) {
        _sdView.frame =CGRectMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH*4-32,_pimageView.frame.origin.y+_pimageView.frame.size.height - 16, 32, 16);
        NSString *siconView =[NSString stringWithFormat:@"%@",[dict objectForKey:@"icon_url"]];
        [_sdView sd_setImageWithURL:[NSURL URLWithString:siconView]];
    }
    fTop = _pimageView.frame.origin.y+_pimageView.frame.size.height+PHOTO_FRAME_WIDTH*2;
    //
    NSString *skuname =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"title"]] replaceNullString];
    if (skuname.length>0) {
        [_skuNameLabel setText:[NSString stringWithFormat:@"%@",skuname]];
   //     CGSize optimumSize = [_skuNameLabel optimumSize];
   //     CGFloat hh =optimumSize.height;
  //      if (hh<20) {
   //         hh=20;
   //     }
        _skuNameLabel.frame = CGRectMake(PHOTO_FRAME_WIDTH,fTop, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, 20);
        _skuNameLine.frame = CGRectMake(PHOTO_FRAME_WIDTH,_skuNameLabel.frame.origin.y+_skuNameLabel.frame.size.height+5, PHOTO_FRAME_WIDTH*2, 1);
        fTop = fTop+20+PHOTO_FRAME_WIDTH*2;
    }else
    {
        _skuNameLine.frame = CGRectZero;
    }
    
    CGFloat hh0 =0;
     NSString *cat =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"cat2"]] replaceNullString];
    if (cat.length>0) {
        [_cateLabel setText:cat];
        CGSize optimumSize10 = [_cateLabel optimumSize];
        hh0 =optimumSize10.height;
        if ([self.key isEqualToString:@"categoryView"]) {
            _cateLabel.textColor = [UIColor darkGrayColor];
            
        }
        _cateLabel.frame =CGRectMake(PHOTO_FRAME_WIDTH,fTop,optimumSize10.width, hh0);
    }
    
    NSString *brand =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"brand"]] replaceNullString];
    if (brand.length>0) {
        brand =[NSString stringWithFormat:@"  /  %@",brand];
        [_brandLabel setText:brand];
        CGSize optimumSize11 = [_brandLabel optimumSize];
        hh0 =optimumSize11.height;
        if ([self.key isEqualToString:@"brandView"]) {
            _brandLabel.textColor = [UIColor darkGrayColor];
        }
        _brandLabel.frame =CGRectMake(_cateLabel.frame.origin.x+_cateLabel.frame.size.width,fTop-1,optimumSize11.width+2, hh0);
    }
    if (cat.length>0 || brand.length>0) {
        fTop = fTop+hh0+PHOTO_FRAME_WIDTH;
    }
  //
    id tag =[dict objectForKey:@"tag"];
    if (tag&& [tag isKindOfClass:[NSArray class]]&&[tag count]>0) {
      
        NSString *tags = [tag objectAtIndex:0];
        [_tagBtn setTitle:tags forState:UIControlStateNormal];
        NSDictionary *attribute = @{NSFontAttributeName:FONT(14)};
        CGSize retSize = [tags boundingRectWithSize:CGSizeMake(100, 0)
                                            options:
                          NSStringDrawingTruncatesLastVisibleLine |
                          NSStringDrawingUsesLineFragmentOrigin |
                          NSStringDrawingUsesFontLeading
                                         attributes:attribute
                                            context:nil].size;
         _tagBtn.frame =CGRectMake(DEVICE_WIDTH -(retSize.width+PHOTO_FRAME_WIDTH)-PHOTO_FRAME_WIDTH,_cateLabel.frame.origin.y,retSize.width+PHOTO_FRAME_WIDTH, 17);
    }
    //
    NSString *text =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"text"]] replaceNullString];
    if (text.length>0) {
        text =[NSString stringWithFormat:@"“%@”",text];
        [_skuNameContent setText:text];
        CGSize optimumSize1 = [_skuNameContent optimumSize];
        _skuNameContent.frame = CGRectMake(PHOTO_FRAME_WIDTH,fTop, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, optimumSize1.height);
        fTop = fTop+optimumSize1.height+PHOTO_FRAME_WIDTH;
    }
    //
    id comments = nil;//[dict objectForKey:@"comments"];
    if (comments && [comments isKindOfClass:[NSArray class]]&&[comments count]>0) {
        NSMutableArray *cmtArray =[NSMutableArray arrayWithArray:comments];
        if ([cmtArray count]>0) {
            CGFloat chight =0.0;
            for (int i =0 ; i<[cmtArray count]; i++) {
                NSDictionary *cDict = [cmtArray objectAtIndex:i];
                NSString *name =[NSString stringWithFormat:@"%@ :",[cDict objectForKey:@"nick_name"]];
                NSString *content =[NSString stringWithFormat:@"“%@”",[cDict objectForKey:@"text"]];
                NSString *ct =[NSString stringWithFormat:@"<font color='#285790'>%@</font> <font color='#808080'>%@ </font>",name,content];
                UITapGestureRecognizer* singleRecognizer4= [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleTapFrom5)];
                RTLabel *nameLabel =[[RTLabel alloc] initWithFrame:CGRectMake(0,0,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
                nameLabel.backgroundColor = [UIColor clearColor];
                nameLabel.textColor = UIColorFromRGB(0x285790);
                nameLabel.textAlignment = NSTextAlignmentLeft;
                nameLabel.font = FONT(14);
                nameLabel.lineSpacing = LSpacing;
                [nameLabel setText:ct];
                CGSize optimumSize = [nameLabel optimumSize];
                nameLabel.frame = CGRectMake(nameLabel.frame.origin.x,
                                            i*chight,
                                            optimumSize.width, optimumSize.height);
                chight = chight+optimumSize.height+PHOTO_TIME_PADDING;
                nameLabel.userInteractionEnabled =YES;
                [nameLabel addGestureRecognizer:singleRecognizer4];
                [_commentView addSubview:nameLabel];
                singleRecognizer4=nil;
                nameLabel=nil;
            }
            _commentView.frame =CGRectMake(PHOTO_FRAME_WIDTH,fTop, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2, chight);
            fTop =fTop +_commentView.frame.size.height+PHOTO_FRAME_WIDTH;
        }
    }else
    {
//         fTop =fTop +PHOTO_TIME_PADDING;
    }
   //
    NSString *nick = [[NSString stringWithFormat:@"%@",[[dict objectForKey:@"user"] objectForKey:@"nick_name"]] replaceNullString];
    if (nick==nil||[nick isEqualToString:@"(null)"]) {
        nick=@"";
    }
    NSDictionary *attribute = @{NSFontAttributeName:FONT(14)};
    CGSize retSize = [nick boundingRectWithSize:CGSizeMake(DEVICE_WIDTH/2, 0)
                                        options:
                      NSStringDrawingTruncatesLastVisibleLine |
                      NSStringDrawingUsesLineFragmentOrigin |
                      NSStringDrawingUsesFontLeading
                                     attributes:attribute
                                        context:nil].size;
    self.userLable.frame =CGRectMake(PHOTO_FRAME_WIDTH,fTop, retSize.width, PHOTO_FRAME_WIDTH*3);
    self.userLable.text =nick;
    
    //
    NSString *upload_dateinfo = [[NSString stringWithFormat:@"%@",[dict objectForKey:@"upload_dateinfo"]] replaceNullString];
    if (upload_dateinfo==nil||[upload_dateinfo isEqualToString:@"(null)"]) {
        upload_dateinfo=@"";
    }
    NSDictionary *attribute1 = @{NSFontAttributeName:FONT(14)};
    CGSize retSize1 = [upload_dateinfo boundingRectWithSize:CGSizeMake(DEVICE_WIDTH/2, 0)
                                                    options:
                       NSStringDrawingTruncatesLastVisibleLine |
                       NSStringDrawingUsesLineFragmentOrigin |
                       NSStringDrawingUsesFontLeading
                                                 attributes:attribute1
                                                    context:nil].size;
    self.timeLable.frame =CGRectMake(self.userLable.frame.origin.x+self.userLable.frame.size.width+PHOTO_FRAME_WIDTH,fTop, retSize1.width, PHOTO_FRAME_WIDTH*3);
    
    self.timeLable.text =upload_dateinfo;
    
    //
    //
   
    NSString *like_cnt =[NSString stringWithFormat:@"%@",[dict objectForKey:@"like_cnt"]];
    if (like_cnt.length>0&&![like_cnt isEqualToString:@"0"]) {
        [_btnLikeV setImage:[UIImage imageNamed:@"like_icon.png"] name:like_cnt];
    }else
    {
        like_cnt =@"喜欢";
        [_btnLikeV setImage:[UIImage imageNamed:@"like_icon.png"] name:@"喜欢"];
    }
    CGSize size2=[like_cnt sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12.0]}];
    
    [_btnLikeV setFrame:CGRectMake(DEVICE_WIDTH-PHOTO_FRAME_WIDTH - (size2.width+25) ,fTop, size2.width+25, MORE_BUTTON_HEIGHT)];
    
    int isLike=[[dict objectForKey:@"like"] intValue];
    if (isLike) {
        [_btnLikeV setImage:[UIImage imageNamed:@"like_icon_selected.png"] name:like_cnt];
        
    }
    //
    NSString *reply_cnt =[NSString stringWithFormat:@"%@",[dict objectForKey:@"reply_cnt"]];
    if (reply_cnt.length>0&&![reply_cnt isEqualToString:@"0"]) {
        [_btnReplyV setImage:[UIImage imageNamed:@"pinglun_icon.png"] name:reply_cnt];
        
    }else{
        reply_cnt =@"点评";
        [_btnReplyV setImage:[UIImage imageNamed:@"pinglun_icon.png"] name:@"点评"];
        
    }
    CGSize size1=[reply_cnt sizeWithAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:12.0]}];
    [_btnReplyV setFrame:CGRectMake(_btnLikeV.frame.origin.x -(size1.width+25)- PHOTO_FRAME_WIDTH ,fTop, size1.width+25, MORE_BUTTON_HEIGHT)];
    
    
//
    if (is_shaidan==0) {
        _priceLabel.frame = CGRectMake(PHOTO_FRAME_WIDTH,fTop, 200, MORE_BUTTON_HEIGHT);
        _priceLabel.text =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"price_str"]] replaceNullString];
    }
    
    
//
    
    [self layoutSubviews];
}


/// 返回Cell高度
+ (CGFloat)returnCellHeight:(id)model
{
    NSDictionary *dict =(NSDictionary*)model;
    float fTop = 0;
    fTop += PHOTO_FRAME_WIDTH*2+PHOTO_TIME_PADDING;
    
    fTop += DEVICE_WIDTH-PHOTO_FRAME_WIDTH*6;
    
    NSString *skuname =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"title"]] replaceNullString];
    CGFloat hight =fTop;
    if (skuname.length>0) {
        RTLabel *text1Label =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        text1Label.font = FONT(16);
        text1Label.lineSpacing = LSpacing;
        [text1Label setText:[NSString stringWithFormat:@"%@",skuname]];
        CGSize optimumSize = [text1Label optimumSize];
         text1Label=nil;
        CGFloat hh1 =optimumSize.height;
        if (hh1<20) {
            hh1=20;
        }
        hight = hight +20+PHOTO_FRAME_WIDTH*2;
    }
    NSString *cat =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"cat2"]] replaceNullString];
    NSString *brand =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"brand"]] replaceNullString];
    if (brand.length>0) {
        cat =[NSString stringWithFormat:@"%@ / %@",cat,brand];
    }
    if (cat.length>0) {
        RTLabel *text2Label =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        text2Label.font = FONT(14);
        text2Label.lineSpacing = LSpacing;
        [text2Label setText:cat];
        CGSize optimumSize2 = [text2Label optimumSize];
         text2Label=nil;
        CGFloat hh1 =optimumSize2.height;
        hight = hight +hh1+PHOTO_FRAME_WIDTH;
    }
    //
    NSString *text =[[NSString stringWithFormat:@"%@", [dict objectForKey:@"text"]] replaceNullString];
    if (text.length>0) {
        text =[NSString stringWithFormat:@"“%@”",text];
        RTLabel *textLabel =[[RTLabel alloc] initWithFrame:CGRectMake(PHOTO_FRAME_WIDTH,0, DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,0)];
        textLabel.font = FONT(14);
        textLabel.lineSpacing = LSpacing;
        [textLabel setText:text];
        CGSize optimumSize1 = [textLabel optimumSize];
         textLabel=nil;
        CGFloat hh1 =optimumSize1.height;
        hight =hight + hh1+PHOTO_FRAME_WIDTH;
    }
    id comments = nil;//[dict objectForKey:@"comments"];
    if (comments && [comments isKindOfClass:[NSArray class]]) {
        NSMutableArray *cmtArray =[NSMutableArray arrayWithArray:comments];
        if ([cmtArray count]>0) {
            CGFloat chight =0.0;
            for (int i =0 ; i<[cmtArray count]; i++) {
                NSDictionary *cDict = [cmtArray objectAtIndex:i];
                NSString *name =[NSString stringWithFormat:@"%@ :",[cDict objectForKey:@"nick_name"]];
                NSString *content =[NSString stringWithFormat:@"“%@”",[cDict objectForKey:@"text"]];
                NSString *ct =[NSString stringWithFormat:@"<font color='#285790'>%@</font> <font color='#808080'>%@ </font>",name,content];
                RTLabel *nameLabel =[[RTLabel alloc] initWithFrame:CGRectMake(0,i*20,DEVICE_WIDTH-PHOTO_FRAME_WIDTH*2,20)];
                nameLabel.backgroundColor = [UIColor clearColor];
                nameLabel.textColor = UIColorFromRGB(0x285790);
                nameLabel.textAlignment = NSTextAlignmentLeft;
                nameLabel.font = FONT(14);
                nameLabel.lineSpacing = LSpacing;
                [nameLabel setText:ct];
                CGSize optimumSize = [nameLabel optimumSize];
                 nameLabel=nil;
                nameLabel.frame = CGRectMake(nameLabel.frame.origin.x,
                                              i*chight,
                                             optimumSize.width, optimumSize.height);
                chight = chight+optimumSize.height+PHOTO_TIME_PADDING;
            }
            hight =hight + chight+PHOTO_FRAME_WIDTH;
        }
    }
    
    hight=hight +MORE_BUTTON_HEIGHT+PHOTO_FRAME_WIDTH;
    return hight;
    
}
-(void)setCallBack:(void(^)(BEventType,UIView*,id,id,NSIndexPath *))callback
{
    self.actionBlock=callback;
}
-(void)categoryAction1:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_categoryTag,sender,self.data,self.tagBtn.titleLabel.text,self.indexPath);
    }
}
-(void)categoryAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_category,sender,self.data,self.key,self.indexPath);
    }
}
-(void)brandAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_brand,sender,self.data,self.key,self.indexPath);
    }
}
-(void)goodAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_good,sender,self.data,self.key,self.indexPath);
    }
}
-(void)likeAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_like,sender,self.data,self.key,self.indexPath);
    }
}
-(void)commentAction:(id)sender
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_comment,sender,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_good,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom3
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_category,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom4
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_brand,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFrom5
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_comment,nil,self.data,self.key,self.indexPath);
    }
}
-(void)handleSingleTapFromUser
{
    if (self.actionBlock) {
        self.actionBlock(BEventType_sunUser,nil,self.data,self.key,self.indexPath);
    }
}
@end
